﻿// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameplayTagContainer.h"
#include "StarrySkyWidgetController.h"
#include "OverlayWidgetController.generated.h"

class UStarrySkyUserWidget;

USTRUCT(BlueprintType)
struct FUIWidgetRow: public FTableRowBase
{
	GENERATED_BODY()
	/*定义弹出消息的标签*/
	UPROPERTY(EditAnywhere,BlueprintReadOnly)
	FGameplayTag MessageTag=FGameplayTag();
	/*定义弹出的消息*/
	UPROPERTY(EditAnywhere,BlueprintReadOnly)
	FText MessageText=FText();
	/*用于UI的类，弹出消息的UI 这里使用TSubclassOf是可以通过蓝图引用直接生成UAuraUserWidget的子类实例,因为之后创建UI需要用到Class*/
	UPROPERTY(EditAnywhere,BlueprintReadOnly)
	TSubclassOf<UStarrySkyUserWidget> MessageWidget;
	/*图标*/
	UPROPERTY(EditAnywhere,BlueprintReadOnly)
	UTexture2D* Icon=nullptr;
};
//广播玩家属性变化的动态多播代理
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnAttributeChangedSingature, float,NewValue);
//广播FUIWidgetRow行消息的动态多播代理,广播一些页面上的提示信息
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FMessageWidgetRowSignature, FUIWidgetRow,Row);
/**
 * 
 */
UCLASS(BlueprintType, Blueprintable)
class STARRYSKY_API UOverlayWidgetController : public UStarrySkyWidgetController
{
	GENERATED_BODY()
public:
	virtual void BroadcastInitialValues() override;
	virtual void BindCallbacksToDependencies() override;

	UPROPERTY(BlueprintAssignable,Category="GAS|Attributes")
	FOnAttributeChangedSingature OnHealthChanged;
	
	UPROPERTY(BlueprintAssignable,Category="GAS|Attributes")
	FOnAttributeChangedSingature OnMaxHealthChanged;

	UPROPERTY(BlueprintAssignable,Category="GAS|Attributes")
	FOnAttributeChangedSingature OnManaChanged;
	
	UPROPERTY(BlueprintAssignable,Category="GAS|Attributes")
	FOnAttributeChangedSingature OnMaxManaChanged;
	
	UPROPERTY(BlueprintAssignable,Category="GAS|Message")
	FMessageWidgetRowSignature MessageWidgetRowDelegate;
protected:
	UPROPERTY(EditDefaultsOnly,BlueprintReadOnly,Category="Widget data")
	TObjectPtr<UDataTable> MessageWidgetDataTable;

	//模板变量，可以通过泛型获取不同表的数据
	template<typename T>
	T* GetDataTableRowByTag(UDataTable* DataTable,const FGameplayTag& Tag) const;
};

template <typename T>
T* UOverlayWidgetController::GetDataTableRowByTag(UDataTable* DataTable, const FGameplayTag& Tag) const
{
	return DataTable->FindRow<T>(Tag.GetTagName(),"",true);
}